﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace Canyala.Lagoon.Effects
{
    public class ResizeEffect
    {
        public static void Animate(FrameworkElement target, double from, double to, int speedRatio, Action finished=null)
        {            
            Storyboard sb = new Storyboard();

            var animationX = new DoubleAnimation
            {
                From = from,
                To = to,
                SpeedRatio = speedRatio
            };

            Storyboard.SetTarget(animationX, target);
            Storyboard.SetTargetProperty(animationX, new PropertyPath("(UIElement.RenderTransform).(CompositeTransform.ScaleX)"));

            sb.Children.Add(animationX);

            var animationY = new DoubleAnimation
            {
                From = from,
                To = to,
                SpeedRatio = speedRatio
            };

            Storyboard.SetTarget(animationY, target);
            Storyboard.SetTargetProperty(animationY, new PropertyPath("(UIElement.RenderTransform).(CompositeTransform.ScaleY)"));

            sb.Children.Add(animationY);
            
            if (finished != null)
                sb.Completed += (s, e) => finished.Invoke();

            sb.Begin();
        }
    }
}
